home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / compiler / globals.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  3.1 KB  |  105 lines  |  [TEXT/MPS ]

  1. (* Global symbol tables *)
  2.  
  3. #open "const";;
  4. #open "prim";;
  5.  
  6. (* A reference to a global, in a source file, is either a qualified identifier
  7.    mod__name, or an unqualified identifier name. *)
  8.  
  9. type global_reference =
  10.     GRname of string
  11.   | GRmodname of qualified_ident
  12. ;;
  13.  
  14. (* Internally, a global is represented by its fully qualified name,
  15.    plus associated information. *)
  16.  
  17. type 'a global =
  18.   { qualid: qualified_ident; (* Full name *)
  19.     info: 'a }               (* Description *)
  20. ;;
  21.  
  22. let little_name_of_global g = g.qualid.id
  23. ;;
  24.  
  25. (* Type constructors *)
  26.  
  27. type type_constr =
  28.   { mutable ty_stamp: int;              (* Stamp *)
  29.     mutable ty_dang: bool;              (* Dangerous or not *)
  30.     mutable ty_abbr: type_abbrev }      (* Abbreviation or not *)
  31.  
  32. and type_abbrev =
  33.     Tnotabbrev
  34.   | Tabbrev of typ list * typ           (* Parameters and body *)
  35.  
  36. (* Type expressions *)
  37.  
  38. and typ =
  39.   { typ_desc: typ_desc;                 (* What kind of type expression? *)
  40.     mutable typ_level: int }            (* Binding level *)
  41. and typ_desc =
  42.     Tvar of mutable typ_link            (* A type variable *)
  43.   | Tarrow of typ * typ                 (* A function type *)
  44.   | Tproduct of typ list                (* A tuple type *)
  45.   | Tconstr of type_constr global * typ list  (* A constructed type *)
  46. and typ_link =
  47.     Tnolink                             (* Free variable *)
  48.   | Tlinkto of typ                      (* Instantiated variable *)
  49. ;;
  50.  
  51. (* Type constructor descriptions *)
  52.  
  53. type type_desc =
  54.   { ty_constr: type_constr global;      (* The constructor *)
  55.     ty_arity: int;                      (* Its arity *)
  56.     mutable ty_desc: type_components }  (* Its description *)
  57.  
  58. and type_components =
  59.     Abstract_type
  60.   | Variant_type of constr_desc global list (* Sum type -> list of constr. *)
  61.   | Record_type of label_desc global list (* Record type -> list of labels *)
  62.   | Abbrev_type of typ list * typ         (* Abbreviation *)
  63.  
  64. (* Value constructors *)
  65.  
  66. and constr_desc =
  67.   { cs_res: typ;                       (* Result type *)
  68.     cs_arg: typ;                       (* Argument type *)
  69.     cs_mut: mutable_flag;              (* Mutable or not *)
  70.     cs_tag: constr_tag;                (* Its run-time tag *)
  71.     cs_kind: constr_kind }             (* How it is represented *)
  72.  
  73. and mutable_flag =
  74.   Mutable | Notmutable
  75.  
  76. and constr_kind =
  77.     Constr_constant                     (* Constant constructor *)
  78.   | Constr_regular                      (* Usual constructor *)
  79.   | Constr_superfluous of int           (* Superfluous constructor
  80.                                            with its arity *)
  81.  
  82. (* Labels *)
  83.  
  84. and label_desc =
  85.   { lbl_res: typ;                      (* Result type *)
  86.     lbl_arg: typ;                      (* Argument type *)
  87.     lbl_mut: mutable_flag;             (* Mutable or not *)
  88.     lbl_pos: int }                     (* Position in the tuple *)
  89. ;;
  90.  
  91. let generic = (-1)
  92. and notgeneric = 0;;
  93.  
  94. (* Global variables *)
  95.  
  96. type value_desc =
  97.   { val_typ: typ;                       (* Type *)
  98.     val_prim: prim_desc }               (* Is this a primitive? *)
  99.  
  100. and prim_desc =
  101.     ValueNotPrim
  102.   | ValuePrim of int * primitive        (* arity & implementation *)
  103. ;;
  104.  
  105.